/**
 * 
 */
package jvs.tea.html;

import java.net.URI;

import x.java.tea.FilterInputStream;
import x.java.tea.MapInjector;

/**
 * @author qiangli
 * 
 */
public class MessageTemplateInputStream extends FilterInputStream {
	private static final String TPL = Constant.TEMPLATE_DIR + "message.htm";
	//private final SimpleDateFormat nowdf = new SimpleDateFormat(
	//		Constant.FULL_DATE_FORMAT);
	protected URI context;
	protected URI asset;
	protected String style;
	protected String basehref;
	protected String iconpath;
	protected String root; // context
	protected String assethref;
	private String title;
	private String message;

	public MessageTemplateInputStream(URI context, URI asset, String title, String message) {
		this.context = (context == null) ? Constant.ROOT_URI : context;
		this.asset = asset;
		this.assethref = asset.toString();
		//
		style = assethref+Constant.STYLE;
		iconpath = assethref+Constant.ICON_PATH;
		basehref = context.toString();
		root = basehref;
		//
		this.title = title;
		this.message = message;
		init();
	}

	private void init() {
		MapInjector map = new MapInjector();
		//
		map.put("title", title);
		map.put("message", message);
		map.put("basehref", basehref);
		map.put("style", style);
		map.put("iconpath", iconpath);
		map.put("assethref", assethref);
		//String now = nowdf.format(new Date());
		//map.put("now", now);
		map.put("appname", jvs.OS.name);
		//map.put("user", "");
		//map.put("jid", "");
		map.put("footer", jvs.OS.copyright);
		//
		map.put("root", root);

		setInjector(map);
		setInputStream(getClass().getResourceAsStream(TPL));
	}
}
